/**
 * Copyleft (C) 2023-2024 maminjie <canpool@163.com>
 * SPDX-License-Identifier: BSD-3-Clause
 **/
#ifndef QXMATERIALRIPPLEOVERLAY_H
#define QXMATERIALRIPPLEOVERLAY_H

#include "matoverlaywidget.h"
#include "qxmaterial_global.h"
#include <QPainterPath>

QX_MATERIAL_BEGIN_NAMESPACE

class MatRipple;

class QX_MATERIAL_EXPORT MatRippleOverlay : public MatOverlayWidget
{
    Q_OBJECT
public:
    explicit MatRippleOverlay(QWidget *parent = 0);
    ~MatRippleOverlay();

    void addRipple(MatRipple *ripple);
    void addRipple(const QPoint &position, qreal radius = 300);

    void removeRipple(MatRipple *ripple);

    inline void setClipping(bool enable);
    inline bool hasClipping() const;

    inline void setClipPath(const QPainterPath &path);
protected:
    void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;

    inline QList<MatRipple *> ripples() const;
private:
    Q_DISABLE_COPY(MatRippleOverlay)

    void paintRipple(QPainter *painter, MatRipple *ripple);

    QList<MatRipple *> m_ripples;
    QPainterPath m_clipPath;
    bool m_useClip;
};

inline void MatRippleOverlay::setClipping(bool enable)
{
    m_useClip = enable;
    update();
}

inline bool MatRippleOverlay::hasClipping() const
{
    return m_useClip;
}

inline void MatRippleOverlay::setClipPath(const QPainterPath &path)
{
    m_clipPath = path;
    update();
}

inline QList<MatRipple *> MatRippleOverlay::ripples() const
{
    return m_ripples;
}

QX_MATERIAL_END_NAMESPACE

#endif   // QXMATERIALRIPPLEOVERLAY_H
